<?php
include("config.php");
if (isset($_POST) && !empty($_POST)) {
	
	$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
	
	if ($db_www->isConnected()) {							
		$get_username = addslashes_mssql($_POST["user_name"]);
		$get_password = addslashes_mssql($_POST["user_password"]);
		$u_query = str_replace("<get_username>", $get_username, $u_query);
		$u_query = str_replace("<get_password>", $get_password, $u_query);					
		$info = $db_www->returnInfo($u_query);									
		if (!empty($info)) {


			$i_query = str_replace("<kodas>", $info["r05_kodas_rs"], $i_query);
			$minfo = $db_www->returnInfo($i_query);				
			
			if (trim($info["grupe"]) != "WEB_ADMIN") {
				$_SESSION['user'] = $info["r05_kodas_rs"];
				$_SESSION['group'] = trim($info["grupe"]);	
				$_SESSION['company'] = @iconv('windows-1257', 'UTF-8', $minfo["N08_PAV"]);	
				$_SESSION['discount'] = trim($minfo["N08_kodas_ls_6"]);	
				include("authdocuwiki.php");
				logAction($_SESSION["user"],6);				
				header('Location: main.php');
			} else {
				$_SESSION['auser'] = $info["r05_kodas_rs"];
				$_SESSION['agroup'] = trim($info["grupe"]);	
				$_SESSION['acompany'] = @iconv('windows-1257', 'UTF-8', $minfo["N08_PAV"]);	
				include("authdocuwiki.php");
				logActionLong($_SESSION['auser'],$_SESSION['acompany'],"Administratorius ".$_SESSION['auser'],6);					
				header('Location: overview.php');
			}
		} else {
			//ieskosim pagal nauja logika
			$admin_query = str_replace("<get_username>", $get_username, $admin_query);
			$admin_query = str_replace("<get_password>", convpsw($_POST["user_password"]), $admin_query);					
			$info = $db_www->returnInfo($admin_query);	

			if (!empty($info)) {
				$_SESSION['auser'] = $info["R05_KODAS_RS"];
				$_SESSION['agroup'] = "WEB_ADMIN";	
				$_SESSION['acompany'] = @iconv('windows-1257', 'UTF-8', $minfo["N08_PAV"]);	
				include("authdocuwiki.php");
				logActionLong($_SESSION['auser'],$_SESSION['acompany'],"Administratorius ".$_SESSION['auser'],6);					
				header('Location: overview.php');
			} else {
				include("header.php");		
		?>						
			<p>Blogas vartotojo vardas ar slaptažodis. <A href="index.php">Bandykite dar kartą</A></p>
		<?php
				logActionLong($_POST["user_name"],"","Blogas vartotojas ar slaptažodis.",8);
			}
		}
	} else {
			include("header.php");	
		?>						
				<p>Klientų aptarnavimo sistema laikinai neveikia. <A href="index.php">Bandykite vėliau</A</p>
		<?php							
	}	
} else {
include("header.php");
$_SESSION['user'] = "";
unset($_SESSION['from']);
unset($_SESSION['to']);
?>		
	
<form name="form1" method="post" action="index.php">
Sveiki atvykę!
<P>
Surinkite vartotojo ID ir slaptažodį.
<P>
<TABLE BORDER=0>
<TR><TD>&nbsp;</TD></TR>
<TR>
	<TD>Vartotojo&nbsp;ID </TD>
	<TD><INPUT TYPE=TEXT NAME="user_name" VALUE="" SIZE=10 MAXLENGTH=20 style="width:100px"></TD>
	</TD>
<TR>
	<TD>Slaptažodis </TD>
	<TD><INPUT TYPE=PASSWORD NAME="user_password" VALUE="" SIZE=10 MAXLENGTH=20 style="width:100px"></TD>

        <TD><A HREF="forgot.php">Pamiršote slaptažodį? Spauskite čia</A></TD>

</TR>
<TR>
	<TD>&nbsp;</TD>
	<TD><INPUT TYPE=SUBMIT VALUE="  OK   "></TD>
</TR>
</TABLE>

<TABLE BORDER=0>
<TR>
        <TD>
        Norėdami peržiūrėti dokumentus,<BR> 
        įdiekite Adobe Acrobat Reader programą.
        </TD>
        <TD>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="http://www.adobe.com/products/acrobat/readstep2.html" TARGET=_new><IMG SRC="./img/getacro.gif" BORDER="0" HEIGHT="33" WIDTH="112" alt="Get Adobe Reader"></A>
        </TD>
</TR>
</TABLE>


Nepavykus prisijungti prie sistemos, rašykite mums el. pašto adresu <A HREF="mailto:<?php echo $client_email?>"><?php echo $client_email?></a> arba skambinkite&nbsp;<?php echo $client_work_hours?>telefonu&nbsp;<?php echo $client_phone?>.
<P>
<SCRIPT>
document.forms[0].user_name.focus(); 
</SCRIPT>
<?php
} 
include("footer.php");
?>